<!-- 渠道选择下拉框 -->
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="jxt.elt.common.DbPool"%>
<%@page import="java.sql.Connection"%>

<%
	String id = request.getParameter("id");
	String name = request.getParameter("name");
	String channel_id = request.getParameter("channel_id");
	String query = request.getParameter("query");
	String readOnly = request.getParameter("readOnly");
	String disabled = request.getParameter("disabled");
	String onchange = request.getParameter("onchange");
	
	if (channel_id == null) {
		channel_id = "";
	}
	Connection conn = DbPool.getInstance().getConnection();
	try {
		Statement stmt = conn.createStatement();

		out.print("<select ");
		
		//attributes
		if(id != null && id.length() > 0){
			out.print("id='"+id+"' ");
		}else {
			out.print("id='channel_id' ");
		}
		
		if(id != null && id.length() > 0){
			out.print("name='"+name+"' ");
		}else {
			out.print("name='channel_id' ");
		}
		
		if(readOnly != null && readOnly.length() > 0){
			out.print("onfocus='this.defOpt=this.selectedIndex' onchange='this.selectedIndex=this.defOpt;' ");
		}
		if(disabled != null && disabled.length() > 0){
			out.print("disabled='disabled' ");
		}
		
		//events
		if(onchange != null && onchange.length() > 0){
			out.print("onchange='"+onchange+"' ");
		}
		
		out.print(">");
		
		if(query != null && query.length() > 0){
			out.print("<option value=''>全部</option>");
		}

		String strsql = "select nid,zhName from tbl_channel order by nid asc";
		ResultSet rs = stmt.executeQuery(strsql);
		while (rs.next()) {
			String selectStr = "<option value='" + rs.getString("nid")
					+ "' ";
			if (channel_id != null
					&& channel_id.equals(rs.getString("nid"))) {
				selectStr += " selected='selected'";
			}
			selectStr += ">"+rs.getString("zhName") + "</option>";
			out.println(selectStr);
		}
		rs.close();
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		if (conn != null) {
			conn.close();
		}
	}
	out.print("</select>");
%>

